package com.travelgroup.controller;

import com.travelgroup.domain.dto.UserGroupDTO;
import com.travelgroup.domain.vo.UserGroupVO;
import com.travelgroup.domain.vo.UserVO;
import com.travelgroup.exception.R;
import com.travelgroup.service.ITourGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user-group")
@Tag(name = "用户拼团模块")
public class UserGroupController {
    @Resource
    private ITourGroupService tourGroupService;

    @PostMapping("/save")
    @Operation(summary = "加入拼团")
    public R<Long> saveUserGroup(@RequestBody UserGroupDTO userGroupDTO) {
        return tourGroupService.saveUserGroup(userGroupDTO);
    }

    @PutMapping("/cancel/{groupId}")
    @Operation(summary = "取消拼团")
    public R<?> cancelUserGroup(@PathVariable Long groupId) {
        return tourGroupService.cancelUserGroup(groupId);
    }

    @GetMapping("/query/me")
    @Operation(summary = "获取我的组队信息")
    public R<List<UserGroupVO>> queryMyUserGroup(@RequestParam(defaultValue = "1") Integer current,
                                                 @RequestParam(defaultValue = "10") Integer size) {
        return tourGroupService.queryMyTourGroup(current, size);
    }

    @GetMapping("/query/user/{groupId}")
    @Operation(summary = "获取进行拼团的用户")
    public R<List<UserVO>> queryUserByGroupId(@PathVariable Long groupId) {
        return tourGroupService.queryUserByGroupId(groupId);
    }

}
